package leetcode.code1807;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public String evaluate(String s, List<List<String>> knowledge) {
		Map<String, String> map = new HashMap<>();
		for (int i = 0; i < knowledge.size(); i++) {
			List<String> know = knowledge.get(i);
			map.put(know.get(0), know.get(1));
		}
		char[] cs = s.toCharArray();
		StringBuffer ans = new StringBuffer();
		for (int i = 0; i < cs.length; i++) {
			char c = cs[i];
			if (c == '(') {
				StringBuffer key = new StringBuffer();
				while (cs[++i] != ')') {
					key.append(cs[i]);
				}
				String value = map.getOrDefault(key.toString(), "?");
				ans.append(value);
			} else {
				ans.append(c);
			}
		}
		return ans.toString();
	}

	@Override
	public void debug4() {


	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
